package com.cmschina.util;

/**
 * @author: li chao
 * @Desc:
 * @create: 2024-08-07 09:50
 **/
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtils {

    public static long stringToTimestamp(String dateString, String format) {
        try {
            SimpleDateFormat sdf = new SimpleDateFormat(format);
            Date date = sdf.parse(dateString);
            return date.getTime();
        } catch (Exception e) {
            e.printStackTrace();
            return 0;
        }
    }

    public static void main(String[] args) {
        String dateString = "2022-01-01 12:12:34.123";
        String format = "yyyy-MM-dd HH:mm:ss.SSS";
        long timestamp = stringToTimestamp(dateString, format);
        System.out.println("毫秒值：" + timestamp);
    }
}